﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataAccessLogic;
using System.Data;

namespace BusinessLogic
{
    [Serializable]
    public class Instrument : Table
    {
        #region Fields
        private InstrumentType _instrumentType;
        private ManufacturerType _manufacturerType;
        private string _model;
        private string _serialNumber;
        private string _unitNumber;
        #endregion

        #region Methods
        public bool Create()
        {
            try
            {
                this._id = InstrumentDataAccess.Create(this);

                if (this._id != Guid.Empty)
                {
                    return true;
                }
            }
            catch
            {
                return false;
            }

            return false;            
        }

        public static List<Instrument> GetAll()
        {
            return InstrumentDataAccess.GetAll();
        }

        public static Instrument GetByID(Guid id)
        {
            return InstrumentDataAccess.GetByID(id);
        }        

        public static DataTable SearchAll()
        {
            return InstrumentDataAccess.SearchAll();
        }
        #endregion

        #region Properties
        public InstrumentType InstrumentType
        {
            get { return _instrumentType; }
            set { _instrumentType = value; }
        }

        public ManufacturerType ManufacturerType
        {
            get { return _manufacturerType; }
            set { _manufacturerType = value; }
        }

        public string Model
        {
            get { return _model; }
            set { _model = value; }
        }

        public string SerialNumber
        {
            get
            {
                return _serialNumber;
            }
            set
            {
                _serialNumber = value;
            }
        }

        public string UnitNumber
        {
            get
            {
                return _unitNumber;
            }
            set
            {
                _unitNumber = value;
            }
        }

        public bool Exists
        {
            get
            {
                bool exists = false;

                if(!string.IsNullOrEmpty(_model) || !string.IsNullOrEmpty(_serialNumber) || !string.IsNullOrEmpty(_unitNumber))
                {
                    exists = true;
                }

                if((_instrumentType != null) || (_manufacturerType != null))
                {
                    if(!string.IsNullOrEmpty(_instrumentType.Description) || !string.IsNullOrEmpty(_manufacturerType.Description) || _instrumentType.ID != Guid.Empty || _manufacturerType.ID != Guid.Empty)
                    {
                        exists = true;
                    }
                }

                return exists;
            }
        }
        #endregion
    }
}